<template>
  <div class="public">
    <el-select
      class="pu-select"
      style="width: 97%"
      v-model="value"
      popper-class="pu-list"
      @change="change"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <div class="pu-Title">
      <div class="titlecolor"></div>
      <div class="pu">
        <h1 class="putitle">{{ title }}</h1>
      </div>
    </div>
    <div class="te-content">
      <template v-if="show == 1">
        <div>稍等</div>
      </template>
      <template v-if="show == 2">
        <div v-for="{ id } in phonetable" :key="id">
          <div v-html="phonetable[id - 1].content"></div>
        </div>
      </template>
      <template v-if="show == 3">
        <iframe
          :src="this.calendar[this.calendar.length - 1].content"
          class="article-pdf"
          @onload="onload()"
          frameborder="0"
        ></iframe>
      </template>
      <template v-if="show == 4">
        <div v-for="{ title, id } in rest" :key="id">
          <p class="rest-title">{{ title }}</p>
          <div v-html="rest[id - 1].content" class="rest-content"></div>
        </div>
      </template>
      <template v-if="show == 5"> </template>
    </div>
  </div>
</template>

<script>
import { TeachingCalendar, phone, rest } from "@/api";
export default {
  name: "Public",
  data() {
    return {
      options: [
        { value: "1", label: "图书馆" },
        { value: "2", label: "联系电话" },
        { value: "3", label: "教学日历" },
        { value: "4", label: "作息时间" },
        { value: "5", label: "表格下载" },
        { value: "6", label: "档案查询流程" },
      ],
      value: this.$route.query.key,
      title: this.$route.query.key,
      show: this.$route.query.show,
      id: this.$route.query.id,
      phonetable: [],
      calendar: [],
      rest: [],
    };
  },
  created() {
    phone().then((res) => {
      this.phonetable = res.data;
    });
    TeachingCalendar().then((res) => {
      this.calendar = res.data;
    });
    rest().then((res) => {
      this.rest = res.data;
    });
  },
  mounted() {
    this.$emit("public1", false);
  },
  beforeDestroy() {
    this.$emit("public", true);
  },
  watch: {
    $route(to, from) {
      this.show = to.query.show;
      this.title = to.query.key;
      this.value = to.query.key;
      this.id = to.query.id;
    },
  },
  methods: {
    change(value) {
      let obj = {};
      obj = this.options.find((item) => {
        return item.value === value;
      });
      this.value = obj.label;
      this.title = this.value;
      this.$router.replace({
        query: { key: this.title, show: obj.value },
      });
      if (obj.value == 1) {
        window.location.href = "https://www.sdwcvc.edu.cn/tsg/";
      } else if (obj.value == 5) {
        window.location.href = "https://www.sdwcvc.edu.cn/bgs/wjxz.htm";
      } else if (obj.value == 6) {
        window.location.href = "https://www.sdwcvc.edu.cn/bgs/dagl.htm";
      } else {
        console.error("Invalid value: ");
      }
    },
    onload() {},
  },
};
</script>

<style>
/* 公共服务 */
.public {
  background: white;
  padding: 0.2rem;
}
/* 标题栏 */
.pu-Title {
  width: 96%;
  border-bottom: 1px solid #084fb0;
  margin: 0.2rem;
}
/* 标题容器 */
.pu {
  display: inline-block;
}
/* 标题 */
.putitle {
  font-size: 0.8rem;
  padding: 0.2rem;
  color: #084fb0;
  font-weight: normal;
}
/* 内容容器 */
.pu-content {
  margin-top: 0.72rem;
}
/* 列表 */
.list-item-public {
  list-style: none;
  line-height: 1rem;
  font-size: 0.56rem;
  padding-left: 0.4rem;
  padding-bottom: 0.36rem;
  border-bottom: 0.04rem dashed #eeeeee;
  margin-bottom: 0.72rem;
}
/* 列表标题 */
.list-item-public .list-item-title {
  width: 88%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 列表时间 */
.list-item-public .list-item-time {
  font-size: 0.4rem;
  color: #c3c3c3;
}
/* 选择框 */
.pu-select .el-input__inner {
  text-align: center;
  background: #084fb0;
  color: white;
  height: 1.5rem;
  font-size: 0.72rem;
}
/* 选择栏容器 */
.pu-list {
  text-align: center;
  background: rgba(0, 0, 0, 0.75);
}
/* 单个选择栏 */
.pu-list .el-select-dropdown__item {
  color: white;
  border-bottom: 1px solid #868686;
  font-size: 0.6rem !important;
  height: auto !important;
  line-height: 1.5rem !important;
}
/* 最后一个选项框去掉底部边框线 */
.pu-list .el-select-dropdown__item:last-child {
  border-bottom: 0;
}
/* 选择框选择栏选中后 */
.pu-list .el-select-dropdown__item.hover {
  background-color: rgba(0, 0, 0, 0.75);
}
/* 作息时间标题 */
.rest-title {
  font-size: 0.8rem;
  text-align: center;
}
/* 作息时间图片 */
.rest-content p img {
  width: 100%;
  margin-top: 0.4rem;
}
.te-content table {
  border: 0.04rem solid #333;
  border-bottom: 0;
}
.te-content th {
  border-right: 0.04rem solid #333;
  border-bottom: 0.04rem solid #333;
  font-size: 0.64rem;
}
.te-content th:last-child {
  border-right: 0;
}
.te-content td {
  border-right: 0.04rem solid #333;
  border-bottom: 0.04rem solid #333;
  font-size: 0.64rem;
}
.te-content td:last-child {
  border-right: 0;
}
</style>
